package com.example.controller;

import com.example.entity.AmountVO;
import com.example.entity.Result;
import com.example.service.IIncomeService;
import com.example.service.IOutcomeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@Slf4j
@CrossOrigin
@RequestMapping("/budget")
@RequiredArgsConstructor
public class BudgetInfo {

    private final IIncomeService iIncomeService;

    private final IOutcomeService iOutcomeService;

    @GetMapping("/baseInfo")
    public Result<AmountVO> baseInfo(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                     @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        Double income = iIncomeService.sumByTime(begin,end);
        Double outcome = iOutcomeService.sumByTime(begin,end);
        return Result.success(new AmountVO(income,outcome));
    }
}
